package youleche.com.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * uicode编码类
 * @author 申鱼川
 *
 */
public class UnicodeUtil {
	/**
	 * unicode编码转中文
	 * @param dataStr 转换字符串
	 * @return 返回该字符串的中文
	 */
	public static String decodeUnicode(final String dataStr ) {
        int start = 0;
        int end = 0;
        final StringBuffer buffer = new StringBuffer();
        while( start > -1 ) {
          end = dataStr.indexOf( "\\u", start + 2 );
          String charStr = "";
          if( end == -1 ) {
            charStr = dataStr.substring( start + 2, dataStr.length() );
          } else {
            charStr = dataStr.substring( start + 2, end);
          }
          char letter = (char) Integer.parseInt( charStr, 16 );
          buffer.append( new Character( letter ).toString() );
          start = end;
        }
        return buffer.toString();
    } 
	
	/**
	 * 判断字符串里面是否包含中文
	 * @param str 需要判断的字符
	 * @return 返回true 包含
	 */
	public static boolean isContainsChinese(String str){
		String regEx = "[\u4e00-\u9fa5]";
		Pattern pat = Pattern.compile(regEx);
		Matcher matcher = pat.matcher(str);
		boolean flg = false;
		if (matcher.find()){
			flg = true;
		}
		
		return flg;
	}
}
